/**
 * 
 */
package com.alstudio.ui.module.props;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.module.xmpp.request.ALUiXmppRequestCreator;
import com.alstudio.pojo.ALXmppEvent;
import com.alstudio.pojo.module.local.Prop;
import com.alstudio.pojo.module.local.Props;
import com.alstudio.pojo.module.local.PropsDetail;
import com.alstudio.ui.base.TitleBarActivity;
import com.alstudio.ui.module.economy.UserWalletActivity;
import com.alstudio.utils.android.net.http.BuyPrivilegeHttpRqWrap;
import com.alstudio.utils.android.net.http.BuyPrivilegeResult;
import com.alstudio.utils.android.net.http.HttpDataAsynHelper;
import com.alstudio.utils.android.net.http.HttpResultWrap;
import com.alstudio.utils.umeng.UmengUtils;
import com.alstudio.view.dialog.AlertDialogCreator;
import com.alstudio.view.listener.AlDialogOnClickListener;
import com.alstudio.view.toast.MyToastUtil;
import com.loovee.imaohu.R;

/**
 * 道具详情
 * 
 * @author alonso lee
 * 
 */
public class PropsDetailActivity extends TitleBarActivity {

	private ImageView props_buy_prop_icon_imageview;
	private TextView props_buy_prop_name_textview;
	private LinearLayout props_buy_prop_content_view;
	private TextView props_buy_desc_content_textview;
	private RelativeLayout props_buy_subscribe_view;
	private TextView props_buy_prop_name_desc_textview;
	private RelativeLayout props_buy_prop_title_view;
	private ImageView image_purchased;

	private TextView props_buy_prop_preview;

	private IntentFilter inf = new IntentFilter();
	private LayoutInflater mInflater = null;

	private ArrayList<Prop> mPropList = new ArrayList<Prop>();
	private Prop mProp = null;
	// 我当前购买的道具
	private Prop mCurProp = null;
	private Prop mDbP = null;

	private int mPropBuyCount = 0;
	private int myBalance = 0;

	private long mTime = 60 * 60 * 24;
	private long mMouthTime = 60 * 60 * 24 * 30;

	// ImageParam param = null;

	private final int PROPSBUYPROPONCLICK = 111; // prop onClick
	private final int PROPSBUYPROPONTOUCH = 222; // prop onTouch
	private final int PROPSBUYPROPSUCCESS = 333; // buy success
	private final int PROPSBUYPROPFAIL = 444; // buy fail
	private final int PROPSBUYPROPERROR = 555; // buy error
	private final int PROPSPRESSDIALOGSHOW = 666;
	private final int PROPSPRESSDIALOGDIMSS = 777;

	private AlertDialogCreator mBuySuccessDialog = null;
	private AlertDialogCreator mBuyFailDialog = null;
	private AlertDialogCreator mBuyDialog = null;
	private AlertDialogCreator mBuyPropsCheckLevelDialg = null;

	private boolean isfinshed = false;
	private boolean isShowEffect = false;// 是否正在预览

	private boolean isZiti = false;
	private boolean isNvShen = false;
	private boolean isBought = false;

	// 购买失败
	private final int BUY_FAIL = 822;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.TitleBarActivity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initData();
		setupView(getApplicationContext(), getClass().getSimpleName());
		fushUIView();
		requeqtData();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.BaseActivity#setupView(android.content.Context,
	 * java.lang.String)
	 */
	@Override
	protected void setupView(Context context, String name) {
		// TODO Auto-generated method stub
		super.setupView(context, name);
		setTitleBarActivityContentView(R.layout.props_detail);
		String title = "";
		if (mProp != null && mProp.getPropName() != null) {
			title = mProp.getPropName();
		}
		setCenterTextViewMessage(title);
		mInflater = ALLocalEnv.getLocalEnv().getGlobalLayoutInflater();

		props_buy_prop_icon_imageview = (ImageView) findViewById(R.id.props_buy_prop_icon_imageview);
		props_buy_prop_name_textview = (TextView) findViewById(R.id.props_buy_prop_name_textview);
		props_buy_prop_name_desc_textview = (TextView) findViewById(R.id.props_buy_prop_name_desc_textview);
		props_buy_prop_content_view = (LinearLayout) findViewById(R.id.props_buy_prop_content_view);
		props_buy_desc_content_textview = (TextView) findViewById(R.id.props_buy_desc_content_textview);
		props_buy_subscribe_view = (RelativeLayout) findViewById(R.id.props_buy_subscribe_view);
		props_buy_prop_title_view = (RelativeLayout) findViewById(R.id.props_buy_prop_title_view);
		image_purchased = (ImageView) findViewById(R.id.image_purchased);

		props_buy_prop_preview = (TextView) findViewById(R.id.props_buy_prop_preview);

		if (isHowepage()) {
			props_buy_prop_preview.setVisibility(View.VISIBLE);
		} else {
			props_buy_prop_preview.setVisibility(View.GONE);
		}
		mInflater = LayoutInflater.from(this);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.BaseActivity#initData()
	 */
	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		mProp = (Prop) getIntent().getSerializableExtra("prop");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.BaseActivity#requeqtData()
	 */
	@Override
	public void requeqtData() {
		// TODO Auto-generated method stub
		super.requeqtData();
		if (ALLocalEnv.isSendXmppDataEnable()) {
			ALUiXmppRequestCreator.postALUiXmppCheckPropsPrice(mProp.getProp());
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		isfinshed = false;
		stopEffects();
		super.onResume();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		stopEffects();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.TitleBarActivity#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		super.onClick(v);
		switch (v.getId()) {
		case R.id.props_buy_prop_preview:
			// showEffects();
			break;
		case R.id.props_buy_prop_title_view:
			showEffects();
			break;
		default:
			break;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.ui.base.BaseActivity#handleGetPropsPriceEvent(com.alstudio
	 * .pojo.ALXmppEvent)
	 */
	@Override
	public void handleGetPropsPriceEvent(ALXmppEvent data) {
		// TODO Auto-generated method stub
		super.handleGetPropsPriceEvent(data);
		dismissLoadingProgress();
		if (data.getResponseCode() == ALXmppEvent.RESPONSE_OK) {
			PropsDetail detail = (PropsDetail) data.getData();
			mPropList.addAll(detail.getPropslist());
			detail.getPropslist().clear();
			mPropBuyCount = detail.getPropBuyCount();
			mCurProp = detail.getCurPorp();
			fushPropUIView();
		}
	}

	// 刷新页面
	private void fushUIView() {

		if (mProp != null) {

			if (!TextUtils.isEmpty(mProp.getPropFileId())) {

				ALLocalEnv.getLocalEnv().displayImagePluginServerlet(
						mProp.getPropFileId(), props_buy_prop_icon_imageview);
			}
			if (!TextUtils.isEmpty(mProp.getPropName())) {
				props_buy_prop_name_textview.setText(mProp.getPropName());
			}
			// 刷新描述内容
			fushPropDescView();

		}

	}

	// 刷新buyListUI
	private void fushPropUIView() {
		props_buy_prop_content_view.removeAllViews();

		String base = "";
		if (mCurProp != null) {

			String propname = "";
			if (mProp != null) {
				propname = mProp.getPropName();
			}

			if (mCurProp != null && mCurProp.getProp() != null
					&& mCurProp.getProp().equals(mProp.getProp())) {
				isBought = true;
				image_purchased.setVisibility(View.VISIBLE);
				base = getString(R.string.TxtPropsBuyedHint);
				base = String.format(base, propname, mPropBuyCount);

			} else {
				image_purchased.setVisibility(View.GONE);
				base = getString(R.string.TxtPropsNotBuyHint);
				base = String.format(base, propname, mPropBuyCount);
			}

			// 已经购买
			if (mCurProp != null && mCurProp.getProp() != null
					&& mCurProp.getProp().equals(mProp.getProp())) {
				image_purchased.setVisibility(View.VISIBLE);
			} else {
				image_purchased.setVisibility(View.GONE);
			}

		} else {
			String propname = "";
			if (mProp != null) {
				propname = mProp.getPropName();
			}
			base = getString(R.string.TxtPropsNotBuyHint);
			base = String.format(base, propname, mPropBuyCount);
		}

		props_buy_prop_name_desc_textview.setText(base);

		int index = 0;
		if (mPropList != null && mPropList.size() > 0) {
			props_buy_prop_content_view.setVisibility(View.VISIBLE);

			for (final Prop p : mPropList) {
				index++;
				View view = mInflater.inflate(
						R.layout.props_buy_prop_item_view, null);

				TextView avgTextView = (TextView) view
						.findViewById(R.id.props_buy_prop_item_avg_textview);
				TextView saveTextView = (TextView) view
						.findViewById(R.id.props_buy_prop_item_save_textview);
				TextView priceTextView = (TextView) view
						.findViewById(R.id.props_buy_prop_item_price_textview);
				if (index == 1) {
					view
							.setBackgroundResource(R.drawable.background_view_rounded_top);

				} else if (index == mPropList.size()) {
					view.setBackgroundResource(R.drawable.background_view_rounded_bottom);
				} else {
					view
							.setBackgroundResource(R.drawable.background_view_rounded_middle);
				}
				if (p != null) {
					avgTextView.setText(getAvgText(p));
					saveTextView.setText(getSaveText(p));
					priceTextView.setText(getPriceText(p));
				}

				if (index == mPropList.size()) {

					if (mDbP != null
							&& mDbP.getPropType().equals(Props.mProp_Sub_type)) {
						saveTextView.setVisibility(View.GONE);
						// priceTextView.setVisibility(View.GONE);
					} else {
						saveTextView.setVisibility(View.GONE);
						priceTextView.setVisibility(View.INVISIBLE);
					}
				}

				avgTextView.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Message msg = mPropsBuyHandler.obtainMessage();
						msg.arg1 = PROPSBUYPROPONCLICK;
						msg.obj = p;

						mPropsBuyHandler.sendMessage(msg);

					}
				});

				props_buy_prop_content_view.addView(view);
			}
		} else {
			props_buy_prop_content_view.setVisibility(View.GONE);
		}
	}

	// 刷新DescUI
	private void fushPropDescView() {

		if (mProp != null && mProp.getProp() != null) {
			{

				if (!TextUtils.isEmpty(mProp.getPropDesc())) {
					props_buy_desc_content_textview.setText(Html.fromHtml(mProp
							.getPropDesc()));
				}

				// 如果是订阅通知
				if (mProp.getProp().equals(Props.mProp_Sub_type)) {
					props_buy_subscribe_view.setVisibility(View.VISIBLE);
				} else {
					props_buy_subscribe_view.setVisibility(View.GONE);
				}
			}
		}
	}

	private void showEffects() {
		MyToastUtil.getInstance().showCenterToastOnCenter("想预览？目前不得！");
		if (!isShowEffect) {
			if (mProp.getProp() != null) {/*
										 * AnimationType type =
										 * AnimationType.TYPE_NULL; if
										 * (mProp.getProp
										 * ().equals("HOMEPAGE_FLOWER")) {//
										 * 樱花飞舞 type =
										 * AnimationType.TYPE_SAKURA; } else if
										 * (mProp.getProp().equals(
										 * "HOMEPAGE_DEFOLIATION")) {// 秋叶飘零
										 * type = AnimationType.TYPE_MAPLE; }
										 * else if
										 * (mProp.getProp().equals("HOMEPAGE_SNOW"
										 * )) {// 雪花纷飞 type =
										 * AnimationType.TYPE_SNOW; } else if
										 * (mProp
										 * .getProp().equals("HOMEPAGE_ROSE"))
										 * {// 玫瑰之约 type =
										 * AnimationType.TYPE_ROSE; } else if
										 * (mProp
										 * .getProp().equals("HOMEPAGE_YIHUOCHONG"
										 * )) { // 萤火虫 type =
										 * AnimationType.TYPE_FIREFLY; } else if
										 * (
										 * mProp.getProp().equals("HOMEPAGE_QIPAO"
										 * )) { // 泡泡 type =
										 * AnimationType.TYPE_BUBBLE; } else if
										 * (mProp.getProp().equals(
										 * "HOMEPAGE_PUGONGYING")) { // 蒲公英 type
										 * = AnimationType.TYPE_PUGONGYING; }
										 * else if (mProp.getProp().equals(
										 * "HOMEPAGE_TIANSHI")) { // 天屎 type =
										 * AnimationType.TYPE_TIANSHI; } else if
										 * (mProp.getProp().equals(
										 * "HOMEPAGE_LANSEYAOJI")) { // 蓝色妖姬
										 * type = AnimationType.TYPE_LANSEYAOJI;
										 * } else if (mProp.getProp().equals(
										 * "HOMEPAGE_LIGHTING")) { // 闪电 type =
										 * AnimationType.TYPE_FLASH; }else
										 * if(mProp
										 * .getProp().equals("HOMEPAGE_BIANFU"
										 * )){ //蝙蝠 type =
										 * AnimationType.TYPE_BAT; }else
										 * if(mProp
										 * .getProp().equals("HOMEPAGE_LIUXINGYUYE"
										 * )){ //流星雨夜 type =
										 * AnimationType.TYPE_METEOR; }else
										 * if(mProp
										 * .getProp().equals("HOMEPAGE_XINGGUANG"
										 * )){ //星光熠熠 type =
										 * AnimationType.TYPE_STAR; }else
										 * if(mProp.getProp().equals(
										 * "HOMEPAGE_HUDIEPIANPIAN")){ //蝴蝶翩翩
										 * type = AnimationType.TYPE_BUTTERFLY;
										 * } if (type !=
										 * AnimationType.TYPE_NULL) {
										 * AnimationUtils
										 * .showAnimationBackground(
										 * PropsBuyPropActivity.this, type);
										 * isShowEffect = true; }
										 */
			}
		} else {
			stopEffects();
		}
	}

	private void stopEffects() {
		isShowEffect = false;
		// AnimationUtils.stopAnimation();
	}

	/**
	 * 是否主页动态
	 * 
	 * @return
	 */
	private boolean isHowepage() {
		if (mProp != null && mProp.getProp() != null) {
			if (mProp.getProp().equals("HOMEPAGE_FLOWER")
					|| mProp.getProp().equals("HOMEPAGE_DEFOLIATION")
					|| mProp.getProp().equals("HOMEPAGE_SNOW")
					|| mProp.getProp().equals("HOMEPAGE_ROSE")
					|| mProp.getProp().equals("HOMEPAGE_HUDIEPIANPIAN")
					|| mProp.getProp().equals("HOMEPAGE_XINGGUANG")
					|| mProp.getProp().equals("HOMEPAGE_LIUXINGYUYE")
					|| mProp.getProp().equals("HOMEPAGE_BIANFU")
					|| mProp.getProp().equals("HOMEPAGE_LIGHTING")
					|| mProp.getProp().equals("HOMEPAGE_LANSEYAOJI")
					|| mProp.getProp().equals("HOMEPAGE_YIHUOCHONG")) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 购买道具
	 * 
	 * @param id
	 */
	private void buyPrivilege(final Prop p) {

		if (!ALLocalEnv.isSendXmppDataEnable()) {
			dismissLoadingProgress();
			return;
		}

		HttpDataAsynHelper.Callback callback = new HttpDataAsynHelper.Callback() {

			@Override
			public void onSuccess(HttpResultWrap data) {
				// TODO Auto-generated method stub
				android.os.Message msg = mPropsBuyHandler.obtainMessage();
				msg.obj = p;

				BuyPrivilegeResult tmp = (BuyPrivilegeResult) data;

				if (data.getResultCode() == HttpResultWrap.RESULT_OK) {
					// 购买成功
					msg.arg1 = PROPSBUYPROPSUCCESS;
				} else {
					// 购买失败
					msg.arg1 = PROPSBUYPROPFAIL;
					msg.arg2 = tmp.getResultCode();

				}
				mPropsBuyHandler.sendMessage(msg);

				android.os.Message dmsg = mPropsBuyHandler.obtainMessage();
				dmsg.arg1 = PROPSPRESSDIALOGDIMSS;
				mPropsBuyHandler.sendMessage(dmsg);
			}

			@Override
			public void onSuccess(Bundle data) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onError(Exception e) {
				// TODO Auto-generated method stub
				android.os.Message msg = mPropsBuyHandler.obtainMessage();
				msg.obj = p;
				msg.arg1 = PROPSBUYPROPERROR;
				mPropsBuyHandler.sendMessage(msg);

				android.os.Message dmsg = mPropsBuyHandler.obtainMessage();
				dmsg.arg1 = PROPSPRESSDIALOGDIMSS;
				mPropsBuyHandler.sendMessage(dmsg);
			}
		};

		buyPrivilege(p.getId(), "props", callback);
	}

	/**
	 * 显示购买确认二次对话框
	 * 
	 * @param id
	 * @author Alonso Lee
	 */
	private void showBuyDialog(final Prop p) {

		int num = 0;
		if (p.getPropDuration() != 0) {
			num = (int) (p.getPropDuration() / mMouthTime);
		}
		String msg = getString(R.string.TxtBuyObjectBaseInfo);

		{
			msg += p.getPropName() + " " + num
					+ getString(R.string.TxtMonthDurtion);
		}
		msg += getString(R.string.TxtCostAlert);
		msg += p.getJindou();
		msg += getString(R.string.TxtGold);

		// View contentView = mInflater.inflate(
		// R.layout.chat_send_gift_diglog_content_view, null);
		// NetworkedCacheableImageView icon = (NetworkedCacheableImageView)
		// contentView
		// .findViewById(R.id.icon);
		// TextView msgtv = (TextView) contentView.findViewById(R.id.msg);
		// CheckBox checkbox = (CheckBox)
		// contentView.findViewById(R.id.checkbox);
		// LinearLayout dialog_content_view2 = (LinearLayout) contentView
		// .findViewById(R.id.dialog_content_view2);
		//
		// Prop fp = App.dbUtil.getPropByProp(p.getProp());
		// if (fp != null) {
		// // 显示图片
		// if (!StringUtil.isEmpty(fp.getPropFileId())) {
		// icon.loadImage(fp.getPropFileId(), false, 0, TAG, false, true);
		//
		// }
		// }
		//
		// // 显示内容
		// msgtv.setText(msg);

		AlertDialogCreator dialog = AlertDialogCreator
				.createTwoButtonNormalDialog(this, false);
		dialog.setMessage(msg);
		dialog.setLeftKeyListener(new AlDialogOnClickListener() {

			@Override
			public void onClick() {
				// TODO Auto-generated method stub
				UmengUtils.markEvent(
						PropsDetailActivity.this,
						UmengUtils.Event.VIEW_PROPS_BUY_DETAIL_INFO,
						new String[] { UmengUtils.ArgName.PROPS_PROP,
								UmengUtils.ArgName.PROPS_NAME,
								UmengUtils.ArgName.PROPS_TYPE },
						new String[] { p.getProp(), p.getPropName(),
								p.getPropTypeName() });

				// 2012-9-28 修改购买方式为http
				buyPrivilege(p);
				showLoadingProgress();
				android.os.Message dmsg = mPropsBuyHandler.obtainMessage();
				dmsg.arg1 = PROPSPRESSDIALOGSHOW;
				mPropsBuyHandler.sendMessage(dmsg);
			}
		});
		dialog.showDialog();

	}

	/**
	 * 显示购买成功对话框
	 * 
	 * @author Alonso Lee
	 */
	private void showBuySuccessDialog(final Prop p) {

	}

	// 检测道具等级对话框
	private void showBuyPropsCheckLevelDialg(final Prop p) {

		String title = p.getPropName();
		String msg = "";

		if (mProp != null) {
			if (mProp.getPropLevel() != mCurProp.getPropLevel()
					|| !mCurProp.getProp().equals(p.getProp())) {
				// 买的相同等级的道具
				String base = getString(R.string.TxtBuyPropsEnquelHint);
				int diffrece = 0;
				if (mCurProp.getPropEndTime() != 0
						&& mCurProp.getPropStartTime() != 0) {

					long dif = mCurProp.getPropEndTime()
							- (System.currentTimeMillis() / 1000);

					if (dif != 0) {

						diffrece = (int) (dif / mTime);
					}
				}

				base = String.format(base, mProp.getPropName(), diffrece + "",
						p.getPropName(), mProp.getPropName(),
						mProp.getPropName(), p.getPropName());

				msg += base;

				AlertDialogCreator dialog = AlertDialogCreator
						.createTwoButtonNormalDialog(this, false);
				dialog.setMessage(msg);
				dialog.setLeftKeyListener(new AlDialogOnClickListener() {

					@Override
					public void onClick() {
						// TODO Auto-generated method stub
						showBuyDialog(p);
					}
				});
				dialog.showDialog();

			} else {
				showBuyDialog(p);

			}
		} else {
			showBuyDialog(p);

		}

	}

	// handler
	private Handler mPropsBuyHandler = new Handler() {

		@Override
		public void handleMessage(android.os.Message msg) {

			if (msg.arg1 == PROPSBUYPROPONCLICK) {

				Prop p = (Prop) msg.obj;

				if (!ALLocalEnv.isSendXmppDataEnable()) {
					return;
				}

				// 获取金币
				getMymoney();

				// 已经购买
				if (isBought) {
					showBuyPropsCheckLevelDialg(p);
				} else {
					// 弹出购买确认框
					showBuyDialog(p);
				}

			} else if (msg.arg1 == PROPSBUYPROPONTOUCH) {
			} else if (msg.arg1 == PROPSBUYPROPSUCCESS) {
				dismissLoadingProgress();
				// 购买成功
				Prop p = (Prop) msg.obj;

				showBuySuccessDialog(p);

			} else if (msg.arg1 == PROPSBUYPROPFAIL) {
				dismissLoadingProgress();
				// 购买失败
				Prop p = (Prop) msg.obj;
				int resultCode = msg.arg2;
				if (resultCode == BUY_FAIL) {
					// 弹出购买失败提示
					showNoEnoughMoneyDialog();
				} else {
					MyToastUtil.getInstance().showCenterToastOnCenter(
							getString(R.string.TxtBuyObjectFail));
				}
			} else if (msg.arg1 == PROPSPRESSDIALOGSHOW) {
				showLoadingProgress();
			} else if (msg.arg1 == PROPSPRESSDIALOGDIMSS) {
				dismissLoadingProgress();
			}

		};

	};

	// 获取平均值
	public String getAvgText(Prop p) {

		int num = 0;
		int avgprice = 0;
		int people = 0;
		String base = "";
		if (p != null) {
			if (p.getPropDuration() != 0) {
				num = (int) (p.getPropDuration() / mMouthTime);
			}
			if (p.getJindou() != null && p.getJindou().length() > 0
					&& p.getJindou().matches("\\d*")) {

				int gold = Integer.parseInt(p.getJindou());
				if (gold != 0) {

					if (mProp.getPropType().equals(Props.mProp_Sub_type)) {

						if (p.getPropPeople() != null
								&& p.getPropPeople().length() > 0
								&& p.getPropPeople().matches("\\d*")) {

							people = Integer.parseInt(p.getPropPeople());

							if (people != 0) {
								avgprice = gold / people;
							}
						} else {
							avgprice = gold / num;
						}
					} else {
						avgprice = gold / num;
					}

				}
			}
		}

		if (num > 1) {
			if (mProp.getPropType().equals(Props.mProp_Sub_type)) {
				base = getString(R.string.TxtAvg) + avgprice
						+ getString(R.string.TxtAvgPricePeople);
			} else {
				base = getString(R.string.TxtAvg) + avgprice
						+ getString(R.string.TxtAvgPriceAvgPerMonth);
			}
		} else {
			base = avgprice + getString(R.string.TxtAvgPriceAvgPerMonth);
		}

		return base;
	}

	// 省多少
	public String getSaveText(Prop p) {
		int save = 0;
		if (p != null) {
			if (p.getPropSave() != 0) {
				save = p.getPropSave();
			}

		}
		String base = getString(R.string.TxtSvaePrice);
		base = String.format(base, save + "");
		base = base + getString(R.string.TxtCon);
		return base;
	}

	// 价格显示
	public String getPriceText(Prop p) {
		int num = 0;
		int gold = 0;
		String base = "";
		if (p != null) {
			if (p.getPropDuration() != 0) {
				num = (int) (p.getPropDuration() / mMouthTime);
			}
			if (p.getJindou() != null && p.getJindou().length() > 0
					&& p.getJindou().matches("\\d*")) {

				gold = Integer.parseInt(p.getJindou());
			}
		}

		base = gold + getString(R.string.TxtGold)
				+ getString(R.string.TxtCossed) + num
				+ getString(R.string.TxtMonthDurtion);

		return base;

	}

	// 关闭对话框
	private void dissDialog() {

		if (mBuyDialog != null) {
			mBuyDialog.dismissDialog();
			mBuyDialog = null;
		}

		if (mBuyFailDialog != null) {

			mBuyFailDialog.dismissDialog();
			mBuyFailDialog = null;

		}

		if (mBuyPropsCheckLevelDialg != null) {

			mBuyPropsCheckLevelDialg.dismissDialog();
			mBuyPropsCheckLevelDialg = null;
		}

		if (mBuySuccessDialog != null) {

			mBuySuccessDialog.dismissDialog();
			mBuySuccessDialog = null;
		}
	}

	// 获取我的金币余额
	public void getMymoney() {
		if (!ALLocalEnv.isSendXmppDataEnable()) {
			return;
		}
		showLoadingProgress();
	}

	private void buyPrivilege(String id, String type,
			HttpDataAsynHelper.Callback callback) {
		BuyPrivilegeHttpRqWrap data = new BuyPrivilegeHttpRqWrap();

		data.setToken(ALLocalEnv.getLocalEnv().getMyAccount().getToken());
		data.setProductId(id);
		data.setChargeType(type);
		data.setUsername(ALLocalEnv.getLocalEnv().getMyAccount().getUserName());

		HttpDataAsynHelper.requestBuyPrivilege(data, callback);
	}

}
